package com.topgay.util;

import java.util.HashMap;

import org.springframework.ui.ModelMap;

import com.topgay.domain.ValueStrings;

public class BoardUtilities {
	//글목록에서 한페이지에 보여질 게시물의 개수
	public static final int CONTENT_PER_PAGE = 10;
	//한 페이지 그룹으로 묶을 페이지의 개수
	public static final int PAGE_PER_PAGEGROUP = 5;
	
	/**
	 * TextArea에서 입력 받은 글 내용을 HTML로 출력 될 때에 맞는 형식으로 변경하는 메소드
	 * 새글등록, 답변글등록, 글 수정시 사용
	 * > - &gt;x
	 * < - &lt;
	 * \n - <br>
	 * 공백 - &nbsp;
	 */
	public static String changeContentForDB(String content){		
		String newContent =  content.replaceAll("<", "&lt;");
		newContent = newContent.replaceAll(">", "&gt;");
		newContent = newContent.replaceAll("\r\n", "<br>");
		newContent = newContent.replaceAll(" ", "&nbsp;");
		return newContent;
	}
	/**
	 * DB 에 저장된 content를 TextArea에 출력할 형식으로 변경
	 * 글수정 폼, 답글 폼 출력시 사용
	 * <br> - \n
	 * &gt; - >
	 * &lt; - <
	 * &nbsp; - 공백
	 */
	public static String changeContentForTextArea(String content){
		String newContent  = content.replaceAll("<br>", "\r\n");
		newContent = newContent.replaceAll("&lt;", "<");
		newContent = newContent.replaceAll("&gt;", ">");
		newContent = newContent.replaceAll("&nbsp;", " ");
		return newContent;
	}
	
	
	/**
	 * Community 제목, 부제 설정
	 * @param map
	 * @param nDivide - 1/2/3/4
	 * @return
	 */
	public static HashMap getCommunityTitleForHashMap(HashMap map, int nDivide){
		String divideText = null;
		String divideTextSub = null;
		
		switch (nDivide) {
		case 1:
			divideText = ValueStrings.getInstance().getTitleHotissue();
			divideTextSub = ValueStrings.getInstance().getTitleSubHotissue();
			break;
		case 2:
			divideText = ValueStrings.getInstance().getTitleFree();
			divideTextSub = ValueStrings.getInstance().getTitleSubFree();
			break;
		case 3:
			divideText = ValueStrings.getInstance().getTitleTip();
			divideTextSub = ValueStrings.getInstance().getTitleSubTip();
			break;
		case 4:
			divideText = ValueStrings.getInstance().getTitleCounsel();
			divideTextSub = ValueStrings.getInstance().getTitleSubCounsel();
			break;

		default:
			break;
		}
		map.put("divideText", divideText);
		map.put("divideTextSub", divideTextSub);
		
		return map;
	}
	/**
	 * Community 제목, 부제 설정
	 * @param model
	 * @param nDivide - 1/2/3/4
	 * @return
	 */
	public static ModelMap getCommunityTitle(ModelMap model, int nDivide){
		String divideText = null;
		String divideTextSub = null;
		
		switch (nDivide) {
		case 1:
			divideText = ValueStrings.getInstance().getTitleHotissue();
			divideTextSub = ValueStrings.getInstance().getTitleSubHotissue();
			break;
		case 2:
			divideText = ValueStrings.getInstance().getTitleFree();
			divideTextSub = ValueStrings.getInstance().getTitleSubFree();
			break;
		case 3:
			divideText = ValueStrings.getInstance().getTitleTip();
			divideTextSub = ValueStrings.getInstance().getTitleSubTip();
			break;
		case 4:
			divideText = ValueStrings.getInstance().getTitleCounsel();
			divideTextSub = ValueStrings.getInstance().getTitleSubCounsel();
			break;

		default:
			break;
		}
		model.addAttribute("divideText", divideText);
		model.addAttribute("divideTextSub", divideTextSub);
		
		return model;
	}
	
	/**
	 * CSCenter 제목, 부제 설정
	 * 
	 * @param model
	 * @param nDivide - 5/6/7/8
	 * @return
	 */
	public static ModelMap getCSCenterTitle(ModelMap model, int nDivide){
		String divideText = null;
		String divideTextSub = null;
		
		switch (nDivide) {
		case 5:
			divideText = ValueStrings.getInstance().getTitleNotice();
			divideTextSub = ValueStrings.getInstance().getTitleSubNotice();
			break;
		case 6:
			divideText = ValueStrings.getInstance().getTitleFaq();
			divideTextSub = ValueStrings.getInstance().getTitleSubFaq();
			break;
		case 7:
			divideText = ValueStrings.getInstance().getTitleQna();
			divideTextSub = ValueStrings.getInstance().getTitleSubQna();
			break;
		case 8:
			divideText = ValueStrings.getInstance().getTitleDeclare();
			divideTextSub = ValueStrings.getInstance().getTitleSubDeclare();
			break;

		default:
			break;
		}
		model.addAttribute("divideText", divideText);
		model.addAttribute("divideTextSub", divideTextSub);
		
		return model;
	}
	
	public static ModelMap getMemberTitle(ModelMap map, String role){
		String divideText = null;
		String divideTextSub = null;
		
		if("user".equals(role)){
			divideText = ValueStrings.getInstance().getTitleMember();
			divideTextSub = ValueStrings.getInstance().getTitleSubMember();
		}else{
			divideText = ValueStrings.getInstance().getTitleMember();
			divideTextSub = ValueStrings.getInstance().getTitleSubMember();
		}
		map.put("divideText", divideText);
		map.put("divideTextSub", divideTextSub);
		
		return map;
	}
	
	
	
}
